﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;



namespace EDMD
{
    public class Utils
    {

        public static int ReplaceNULL = -1;

        #region "isnull"
        public static int IsNull(int? value) { if (!value.HasValue) { value = ReplaceNULL; } return (int)value; }
        public static Int64 IsNull(Int64? value) { if (!value.HasValue) { value = ReplaceNULL; } return (Int64)value; }
        public static bool IsNull(bool? value) { if (value == null) { value = false; } return (bool)value; }
        public static string IsNull(string value) { return value ?? string.Empty; }
        public static DateTime IsNull(DateTime? value) { return value ?? DateTime.MinValue; }
        #endregion

        #region "reverseisnull"
        public static int? ReverseIsNull(int value) { if (value == ReplaceNULL) return null; else return value; }
        public static Int64? ReverseIsNull(Int64 value) { if (value == ReplaceNULL) return null; else return value; }
        public static bool? ReverseIsNull(bool value) { return value; }
        public static string ReverseIsNull(string value) { return value; }
        public static DateTime? ReverseIsNull(DateTime value) { if (value == DateTime.MinValue) return null; else return value; }
        #endregion



        public static i7SR.CalendarItem ConvertCalendarItem(CalendarItem CalendarItem_in_ServerFormat)
        {
            return new i7SR.CalendarItem()
            {
                CalendarItem_ID = CalendarItem_in_ServerFormat.CalendarItem_ID,
                CalendarItem_Calendar_ID = CalendarItem_in_ServerFormat.CalendarItem_Calendar_ID,
                Verb_ID = CalendarItem_in_ServerFormat.Verb_ID,
                Entry_ID = CalendarItem_in_ServerFormat.Entry_ID,
                Entry_Name = CalendarItem_in_ServerFormat.Entry_Name,
                Status_ID = CalendarItem_in_ServerFormat.Status_ID,
                StatusNote = CalendarItem_in_ServerFormat.StatusNote,
                isNoDate = CalendarItem_in_ServerFormat.isNoDate,
                isAllDay = CalendarItem_in_ServerFormat.isAllDay,
                isNote = CalendarItem_in_ServerFormat.isNote,
                isRollover = CalendarItem_in_ServerFormat.isRollover,
                isSpan = CalendarItem_in_ServerFormat.isSpan,
                isEmailConfirmRequired = CalendarItem_in_ServerFormat.isEmailConfirmRequired,
                Start_Date = CalendarItem_in_ServerFormat.Start_Date,
                End_Date = CalendarItem_in_ServerFormat.End_Date,
                Create_Date = CalendarItem_in_ServerFormat.Create_Date,
                Update_Date = CalendarItem_in_ServerFormat.Update_Date,
                Created_User_ID = CalendarItem_in_ServerFormat.Created_User_ID,
                Updated_User_ID = CalendarItem_in_ServerFormat.Updated_User_ID,
                GUID = CalendarItem_in_ServerFormat.GUID,
                Salutation = CalendarItem_in_ServerFormat.Salutation,
                FirstName = CalendarItem_in_ServerFormat.FirstName,
                MiddleName = CalendarItem_in_ServerFormat.MiddleName,
                LastName = CalendarItem_in_ServerFormat.LastName
            };
        }//public static i7SR.CalendarItem ConvertCalendarItem(CalendarItem CalendarItem_in_ServerFormat)

        public static i7SR.CalendarItem_Field ConvertCalendarItem_Field(CalendarItem_Field CalendarItem_Field_in_ServerFormat)
        {
            return new i7SR.CalendarItem_Field()
                        {
                            CalendarItem_Field_ID = CalendarItem_Field_in_ServerFormat.CalendarItem_Field_ID,
                            CalendarItem_ID = CalendarItem_Field_in_ServerFormat.CalendarItem_ID,
                            Field_ID = CalendarItem_Field_in_ServerFormat.Field_ID,
                            Value = CalendarItem_Field_in_ServerFormat.Value,
                            Sort = CalendarItem_Field_in_ServerFormat.Sort,
                            GUID = CalendarItem_Field_in_ServerFormat.GUID,
                            Field_Details_ID = CalendarItem_Field_in_ServerFormat.Field_Details_ID
                        };
        }//public static i7SR.CalendarItem_Field ConvertCalendarItem_Field(CalendarItem_Field CalendarItem_Field_in_ServerFormat)

        public static i7SR.vw_CalendarItem_Note Convertvw_CalendarItem_Note(vw_CalendarItem_Note vw_CalendarItem_Note_in_ServerFormat)
        {
            return new i7SR.vw_CalendarItem_Note()
            {
                CalendarItem_Note_ID = vw_CalendarItem_Note_in_ServerFormat.CalendarItem_Note_ID,
                CalendarItem_ID = vw_CalendarItem_Note_in_ServerFormat.CalendarItem_ID,
                Sort = vw_CalendarItem_Note_in_ServerFormat.Sort,
                Type_ID = vw_CalendarItem_Note_in_ServerFormat.Type_ID,
                Type_Name = vw_CalendarItem_Note_in_ServerFormat.Type_Name,
                Note_ID = vw_CalendarItem_Note_in_ServerFormat.Note_ID,
                GUID = vw_CalendarItem_Note_in_ServerFormat.GUID,
                Note = vw_CalendarItem_Note_in_ServerFormat.Note,
            };
        }//public static i7SR.vw_CalendarItem_Note Convertvw_CalendarItem_Note(vw_CalendarItem_Note vw_CalendarItem_Note_in_ServerFormat)

    }//public class Utils
}//namespace EDMD